package de.ostfalia.robotik.rob3;

import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;

import de.ostfalia.robotik.rob3.Rob3.Axis;

/**
 * Ganz einfache GUI um dem Roboter eingegebene Punkte ansteuern zu lassen
 * 
 */
public class SimGui extends JFrame {

	/**
	 * 
	 */
	private static final long serialVersionUID = -5421087994205026537L;

	public static void main(String[] args) {
		// Rob3 rob = null;
		//
		// try {
		// rob = new Rob3("COM1");
		// } catch (NoSuchPortException | PortInUseException
		// | RobotNotAnsweringException e) {
		// e.printStackTrace();
		// System.exit(1);
		// }

		Kinematics sim = new Kinematics();

		sim.zero_x();
		


	}

	public SimGui(final Kinematics arm) {

		setSize(400, 400);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setLocationByPlatform(true);

		JPanel p = new JPanel(new GridLayout(6, 1));

		final JTextField tX = new JTextField();
		final JTextField tY = new JTextField();
		final JTextField tZ = new JTextField();
		final JTextField tGripAngle = new JTextField();
		final JTextArea lRob = new JTextArea("ROB");

		JButton bSetArm = new JButton("SetArm");
		bSetArm.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				arm.setArm(Double.valueOf(tX.getText()),
						Double.valueOf(tY.getText()),
						Double.valueOf(tZ.getText()),
						Double.valueOf(tGripAngle.getText()));
				lRob.setText("Base-Angle= "
						+ arm.getRob().getAxisAngle(Axis.Base)
						+ System.lineSeparator() + "Shoulder-Angle= "
						+ arm.getRob().getAxisAngle(Axis.Shoulder)
						+ System.lineSeparator() + "Elbow-Angle= "
						+ arm.getRob().getAxisAngle(Axis.Elbow)
						+ System.lineSeparator() + "Tool_Pitch= "
						+ arm.getRob().getAxisAngle(Axis.Tool_Pitch)
						+ System.lineSeparator() + "Tool_Roll= "
						+ arm.getRob().getAxisAngle(Axis.Tool_Roll)
						+ System.lineSeparator() + "Gripper= "
						+ arm.getRob().getAxisAngle(Axis.Gripper));
			}
		});

		p.add(tX);
		p.add(tY);
		p.add(tZ);
		p.add(tGripAngle);
		p.add(bSetArm);
		p.add(new JScrollPane(lRob));

		setLayout(new BorderLayout());
		add(p, BorderLayout.CENTER);

		setVisible(true);

	}

}
